import { ResearchRecordItem } from "./typings/index";
import { isEmpty, isNumber } from "./utils";


//样线类-重要值计算
//植物样线、兽类样线/样点、鸟类样线/样点/分区直数、两爬样线、昆虫样线/样点和鱼类调查数据
const calculateResearchLineImportantValue = (
    record: ResearchRecordItem
) => {
    //求出这条样线种的每个物种的重要值
    //relativeDensity 相对密度
    //relativeFrequency 相对频度
    const {
        serialNumberAndCode,
        researchType,
        rowDataList,
    } = record;
    //物种1，数据条数：10 次 ｜ 物种2，数据条数：20 次
    //总数据条数
    //-----
    //物种1, 总数量 20个，物种 2， 总数据 30个
    //所有物种数量之和
    let researchLineTotalSpeciesCount = 0;  //物种数量总和
    let researchLineTotalRowDataCount = 0;  //物种种类
    let speciesRecordList: { speciesName: string, count: number, times: number }[] = [];
    rowDataList.forEach(row => {
        researchLineTotalRowDataCount++;
        if (
            !isEmpty(row.speciesName) &&
            row.speciesName !== '待鉴定'
        ) {
            let findIndex = -1;
            for (let i = 0; i < speciesRecordList.length; i++) {
                if (speciesRecordList[i].speciesName == row.speciesName) {
                    findIndex = i;
                    break;
                }
            }
            //如果有物种数量
            if (isNumber(row.speciesCout)) {
                researchLineTotalSpeciesCount += Number(row.speciesCout);
                if (findIndex > -1) {
                    speciesRecordList[findIndex].count += Number(row.speciesCout);
                    speciesRecordList[findIndex].times++;
                } else {
                    speciesRecordList.push({
                        speciesName: row.speciesName,
                        count: Number(row.speciesCout),
                        times: 1,
                    })
                }
            } else {
                if (findIndex > -1) {
                    speciesRecordList[findIndex].times++;
                } else {
                    speciesRecordList.push({
                        speciesName: row.speciesName,
                        count: 0,
                        times: 1,
                    })
                }
            }
        }
    })
    console.log("这条样线的数据状态是:::", serialNumberAndCode, speciesRecordList)
}

//样地类-重要值计算
// const 

//样地类
const createImportantValueAnalysis = (
    researchRecordList: ResearchRecordItem[],
    type: 'merged' | 'divided'
) => {
    try {
        researchRecordList.forEach(record => {
            if(
                record.researchType == 'beastResearchLine' ||
                record.researchType == 'beastResearchPoint' ||
                record.researchType == 'birdResearcDisPoint' ||
                record.researchType == 'birdResearchLine' ||
                record.researchType == 'birdResearchPoint' ||
                record.researchType == 'fishResearchPoint' ||
                record.researchType == 'insectResearchLine' ||
                record.researchType == 'insectResearchPoint' ||
                record.researchType == 'plantResearchLine' ||
                record.researchType ==  'reptileResearchLine' ||
                record.researchType == 'vegetationResearchPoint'
            ){
                calculateResearchLineImportantValue(record)
            }else if(
                record.researchType == 'forestResearchPlot' ||
                record.researchType == 'grassResearchPlot' ||
                record.researchType == 'shrubResearchPlot'
            ){
                
            }
        })
    } catch (e) {

    }
}

export default createImportantValueAnalysis;